package com.mall.b2c.domain.goods;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.mall.b2c.util.SettingUtils;
import org.hibernate.annotations.Where;
import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mall.common.domain.PriorityEntity;

/**
 * 品牌
 * @author wangzx
 */
@Entity
@Table(name="b2c_brand")
public class BrandDomain extends PriorityEntity {
	private static final long serialVersionUID = 1243744835144402912L;

	@Field(index = Index.UN_TOKENIZED, name = "name", store = Store.YES)
	private String name;//名称
	private String logo;//logo
	private String advert;//首页推荐展示图片
	private String url;//网址
	private String introduction;//介绍
	private Boolean isRecommend;//是否推荐

	@JsonIgnore
	@ContainedIn
	private Set<GoodsDomain> goodsSet;


	@Transient
	public String getPath(){
		return SettingUtils.get().getUrlBuff(true).append("/brand-").append(getId()).append(".jhtml").toString();
	}

	/**
	 * 商品数量
	 * @return
	 */
	@Transient
	public Integer getGoodsQuantity(){
		if(goodsSet == null
				|| goodsSet.isEmpty()){
			return 0;
		}
		return goodsSet.size();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLogo() {
		return logo;
	}

	public void setLogo(String logo) {
		this.logo = logo;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(length=1000)
	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public Boolean getIsRecommend() {
		return isRecommend;
	}

	public void setIsRecommend(Boolean isRecommend) {
		this.isRecommend = isRecommend;
	}
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "brand")
	@Where(clause="isMarketable=1")
	public Set<GoodsDomain> getGoodsSet() {
		return goodsSet;
	}

	public void setGoodsSet(Set<GoodsDomain> goodsSet) {
		this.goodsSet = goodsSet;
	}

	public String getAdvert() {
		return advert;
	}

	public void setAdvert(String advert) {
		this.advert = advert;
	}

}
